<?php
session_start();
if ($_SESSION['Status'] != '1') {
    header('Location: signup.php');
}
$id = $_SESSION['name'];

$query = "SELECT * FROM acedamic_year WHERE Users_email = '$id'";
include "dbconnection.php";
if (!$result = mysql_query($query))
    die("Could not execute query<br/>" . mysql_error());
include "dbconnectionclose.php";
?>
<div class="page">
    <div class="page-header" >
        <div class="page-header-content">
            <div>
                <h1 style="width: 100%;" >Classes</h1>
            </div>
        </div>
    </div>
    <div class="" style="width: 100%; padding-right: -10px;">
        <button class="bg-color-blue fg-color-white button place-right" id="addClasses">New Class</button>
        <button class="bg-color-grayDark fg-color-white button place-right" id="addSubs">Manage Subjects</button>
        <button class="bg-color-grayDark fg-color-white button place-right" id="addTerms">Manage Terms</button>
        <button class="bg-color-grayDark fg-color-white button place-right" id="addYears">Manage Years</button>
    </div>
</div>
<div class="page">
    <div class="page-region">
        <div class="page-region-content">
            <div class="grid">
                <div class="row">
                    <div class="span6">
                        <div style="height: auto; width: 100%;">
                            <button class="span3 image-button bg-color-teal fg-color-white">Filter by Year<i class="icon-filter bg-color-red"></i></button>
                            <button class="span3 image-button bg-color-teal fg-color-white">Filter by Subject<i class="icon-filter bg-color-red"></i></button>
                        </div>
                        <div class="span6">

                            <blockquote onclick='details()' class='tertiary-text padding15 bg-color-blueLight fg-color-blueDark' style='margin-bottom: 10px;  border-left-color: blue;'><p>$row[s_date]."-".$row[e_date]</p></blockquote>
                            <?php
                            for ($counter = 0; $row = mysql_fetch_array($result); $counter++) {
                                $y_id = $row['ayear_id'];
                                print("<blockquote onclick='details()' class='tertiary-text padding15 bg-color-blueLight fg-color-blueDark' style='margin-bottom: 10px; border-left-color: blue;'>$row[ayear_name]</blockquote>");
                            }
                            ?>
                        </div>
                        <div class="span6">
                            <ul class="accordion dark" data-role="accordion">
                                <li class="active">
                                    <a href="#"> Caption </a>
                                    <div style="display: block;"> ...content... </div>
                                </li>
                                <li>
                                    <a href="#"> Caption </a>
                                    <div> ...content... </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <div class="span6 bg-color-blueLight" style="min-height: 500px;">
                        
         <!----------------------------------- Add Class ---------------------------------->
                        <div style="margin: 10px 10px 10px 10px; display: none;" class="bg-color-lighten" id="addCls">
                            <div class="nav-bar bg-color-teal">
                                <div class="nav-bar-inner">
                                    <h3 class="place-left fg-color-white"><strong>New Class</strong></h3>
                                </div>
                            </div>
                            <form class="no-border" id="formClass">
                                <table style="border-color: black;">
                                    <tr class="input-control text">
                                        <td><label>Class:</label></td>
                                        <td><input class="with-helper" id="subject" type="text" autofocus="" placeholder=""/></td>
                                    </tr>
                                    <tr>
                                        <td><label>Date:</label></td>
                                        <td><input type="text" autofocus="" name="Date" placeholder=""/></td>
                                    </tr>
                                    <tr>
                                        <td><label>Start time:</label></td>
                                        <td><input type="text" autofocus="" name="s_time" placeholder=""/></td>
                                    </tr>
                                    <tr>
                                        <td><label>End time:</label></td>
                                        <td><input class="with-helper input-control text" name="e_time" type="text" autofocus="" placeholder=""/></td>
                                    </tr>
                                    <tr>
                                        <td><label>Class Room</label></td>
                                        <td><input class="with-helper input-control text" name="e_time" type="text" autofocus="" placeholder=""/></td>
                                    </tr>
                                    <tr>
                                        <td></td>
                                        <td>
                                            <button class="bg-color-teal fg-color-white button place-right" id="clsSave">Save</button>
                                            <button class="bg-color-grayDark fg-color-white button place-right" id="clsCancel">Cancel</button>
                                        </td>
                                    </tr>
                                </table>
                            </form>
                        </div>
         
       <!------------------------- View Class --------------------------------------------->
                        <div style="margin: 10px 10px 10px 10px; display: none;" class="bg-color-lighten" id="viewCls">
                            <div class="nav-bar bg-color-teal">
                                <div class="nav-bar-inner">
                                    <h3 class="place-left fg-color-white"><strong>Class</strong></h3>
                                </div>
                            </div>
                            <div>

                            </div>
                        </div>
       <!------------------------- Add Year --------------------------------------------->
       <div style="margin: 10px 10px 10px 10px; display: none;" class="bg-color-lighten" id="addCls">
                            <div class="nav-bar bg-color-teal">
                                <div class="nav-bar-inner">
                                    <h3 class="place-left fg-color-white"><strong>New Class</strong></h3>
                                </div>
                            </div>
                            <form class="no-border" id="formClass">
                                <table style="border-color: black;">
                                    <tr class="input-control text">
                                        <td><label>Class:</label></td>
                                        <td><input class="with-helper" id="subject" type="text" autofocus="" placeholder=""/></td>
                                    </tr>
                                    <tr>
                                        <td><label>Date:</label></td>
                                        <td><input type="text" autofocus="" name="Date" placeholder=""/></td>
                                    </tr>
                                    <tr>
                                        <td><label>Start time:</label></td>
                                        <td><input type="text" autofocus="" name="s_time" placeholder=""/></td>
                                    </tr>
                                    <tr>
                                        <td><label>End time:</label></td>
                                        <td><input class="with-helper input-control text" name="e_time" type="text" autofocus="" placeholder=""/></td>
                                    </tr>
                                    <tr>
                                        <td><label>Class Room</label></td>
                                        <td><input class="with-helper input-control text" name="e_time" type="text" autofocus="" placeholder=""/></td>
                                    </tr>
                                    <tr>
                                        <td></td>
                                        <td>
                                            <button class="bg-color-teal fg-color-white button place-right" id="clsSave">Save</button>
                                            <button class="bg-color-grayDark fg-color-white button place-right" id="clsCancel">Cancel</button>
                                        </td>
                                    </tr>
                                </table>
                            </form>
                        </div>
       <script type="text/javascript">
           $(document).ready(function(){
               $('#addClasses').click(function(){
                  document.getElementById('addCls').style.display = "block"; 
               });
               
           });
       </script>
         
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        $('#addYears').click(function(e) {
            $.Dialog({
                'title'      : 'Add Academic Year',
                'draggable': true,
                'content'    : '<form id="acyr"><table>'+
                    '<tr><td><p><label>Academic Year:</label></td><td><input class="with-helper input-control text" name="acYrName" type="text" autofocus="" placeholder="ex: 2012/2013"/></p></td></tr>'+
                    '<tr><td><p><label>Start Date:</label></td><td><input id="" type="text" name="startDate" placeholder="Start Date" /></p></td></tr>'+
                    '<tr><td><p><label>End Date:</label></td><td><input type="text" autofocus="" name="endDate" placeholder="End Date"/></p></td></tr>'+
                    '</table></form>',
                'buttons'    : {
                    'Ok'    : {
                        'action': function() {
                            var data_acyr = $('#acyr').serialize();
                            $.ajax({
                                url:'manageacyr.php',
                                type:"POST",
                                data: data_acyr,
                                success:function(data){
                                    var pagedata = $(data);
                                    if(pagedata.find("h4").html()=="Successful!"){
                                        alert("success");
                                        alert(pagedata.html());
                                    }else{
                                        alert(pagedata.html());
                                    }
                                }
                            });
                        }
                    },
                    'Cancel'     : {
                        'action': function() {}
                    }
                }
            });
        });
        
        $('#addTerms').click(function(e) {
            $.Dialog({
                'title'      : 'Add Semester/Term',
                'draggable': true,
                'content'    :'<div class="span6"><form id=sem style="border"><table>'+
                    '<tr><td><p><label>Semester:</label></td><td><input class="with-helper input-control text" name="SemName" type="text" autofocus="" placeholder="Semester"/></p></td></tr>'+
                    '<tr><td><p><label>Start Date:</label></td><td><input type="text" autofocus="" name="startDate" placeholder="Start Date"/></p></td></tr>'+
                    '<tr><td><p><label>End Date:</label></td><td><input type="text" autofocus="" name="endDate" placeholder="End Date"/></p></td></tr>'+
                    '<tr><td><p><label>Academic Year:</label></td><td><select name="acYr" ><option>vlaue01</option><option>value02</option><option>value03</option></select></p>'+
                    '<tr><td><p><label>Description:</label></td><td><input type="text" autofocus="" name="Desc" placeholder="End Date"/></p></td></tr>'+
                    '</table></form></div>',
                'buttons'    : {
                    'Ok'    : {
                        'action': function() {
                            var data_sem = $('#sem').serialize();
                            alert(data_sem);
                            $.ajax({
                                url:'manageSem.php',
                                type:"POST",
                                data: data_sem,
                                success:function(data){
                                    var pagedata = $(data);
                                    if(pagedata.find("h4").html()=="Successful!"){
                                        alert("success");
                                        alert(pagedata.html());
                                    }else{
                                        alert(pagedata.html());
                                    }
                                }
                            });
                        }
                    },
                    'Cancel'     : {
                        'action': function() {}
                    }
                }
            });
        });
        
        $('#addSubs').click(function(e) {
            $.Dialog({
                'title'      : 'Add Subject',
                'draggable': true,
                'content'    : '<html><body><div class="span5"><form id="sub"><table>'+
                    '<tr><td><p><label>Subject:</label></td><td><input class="with-helper input-control text" id="acYrName" type="text" autofocus="" placeholder="Subject"/></p></td></tr>'+
                    '<tr><td><p><label>Subject ID:</label></td><td><input type="text" autofocus="" id="startDate" placeholder="IMMG0000"/></p></td></tr>'+
                    '<tr><td><p><label>Semester:</label></td><td><select><option>vlaue01</option><option>value02</option><option>value03</option></select></p>'+
                    '<tr><td><p><label>Description:</label></td><td><input type="text" autofocus="" id="description"/></p></td></tr>'+
                    '</table></form></div></body></html>',
                'buttons'    : {
                    'Ok'    : {
                        'action': function() {
                            var data_sem = $('#sub').serialize();
                            alert(data_sem);
                            $.ajax({
                                url:'manageSem.php',
                                type:"POST",
                                data: data_sem,
                                success:function(data){
                                    var pagedata = $(data);
                                    if(pagedata.find("h4").html()=="Successful!"){
                                        alert("success");
                                        alert(pagedata.html());
                                    }else{
                                        alert(pagedata.html());
                                    }
                                }
                            });
                        }
                    },
                    'Cancel'     : {
                        'action': function() {}
                    }
                }
            });
        });
        
        $('#addClass').click(function(e) {
            $.Dialog({
                'title'      : 'Add Class',
                'draggable'  : true,
                'content'    : '<form><table style="border-color: white;">'+
                    '<tr><td><p><label>Subject:</label></td><td><input class="with-helper input-control text" id="subject" type="text" autofocus="" placeholder="ex: 2012/2013"/></p></td></tr>'+
                    '<tr><td><p><label>Date:</label></td><td><input type="text" autofocus="" name="Date" placeholder=""/></p></td></tr>'+
                    '<tr><td><p><label>Start time:</label></td><td><input type="text" autofocus="" name="s_time" placeholder=""/></p></td></tr>'+
                    '<tr><td><p><label>End time:</label></td><td><input class="with-helper input-control text" name="e_time" type="text" autofocus="" placeholder=""/></p></td></tr>'+
                    '</table></form>',
                'buttons'    : {
                    'Ok'    : {
                        'action': function() {
                        }
                    },
                    'Cancel'     : {
                        'action': function() {}
                    }
                }
            });
        });
    });
                                   
</script>